package com.geektime.hello;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: DRevelation
 * @Date: 2020/12/21 14:18
 */
public class ScheduledThreadDemo {

    private static final ScheduledExecutorService executor =
            new ScheduledThreadPoolExecutor(2);

    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {
        List<String> list = Arrays.asList("a", "b", "c");
        for (String s : list) {
            executor.scheduleWithFixedDelay(() -> {
                System.out.println(sdf.format(new Date()));
                System.out.println("======send msg======" + s);
            }, 1, 1, TimeUnit.SECONDS);
        }
    }

}
